/**
 * @file FileLogAppender.h
 * @author  haifeng (haifengxiao@icloud.com)
 * @brief
 * @version 0.1
 * @date 2021-07-06
 *
 * @copyright Copyright (c) 2021
 *
 */

#pragma once

#include <string>
#include <iostream>
#include <fstream>

#include "LogAppender.h"

namespace Chen {
    namespace Log {

        class FileLogAppender : public LogAppender {
        public:
            typedef std::shared_ptr<FileLogAppender> ptr;

            /**
             * @brief Construct a new File Log Appender object
             *
             * @param filename
             */
            FileLogAppender(const std::string& filename);

            /**
             * @brief Write log
             *
             * @param logger logger
             * @param level log level
             * @param event log event
             */
            virtual void log(std::shared_ptr<Logger> logger
                , LogLevel::Level level, LogEvent::ptr event) override;

            /**
             * @brief if the file has been epened
             *
             * @return true
             * @return false
             */
            bool reopen();
        private:
            /// filename
            std::string m_filename;
            /// filesteam 
            std::ofstream m_filestream;
            /// last opening time  
            uint64_t m_lastTime;
        };

    }//namespace Log
}//namespace Chen

